package com.web.wefun.service.impl;

import com.web.wefun.dao.UserMapper;
import com.web.wefun.entity.User;
import com.web.wefun.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    //@Autowired
    @Resource
    private UserMapper userMapper;

    @Override
    public boolean resetPassword(String password) {
        return userMapper.resetPassword(password);
    }

    @Override
    public boolean findUserByName(String username) {
        if (username != null && username.length() > 0) {
            //使用用户名查询数据库有没有对应数据
            //如果返回的List<Emp>时候查不到数据不为Null,只是size大小为0
            List<User> userList = userMapper.getUserByName(username);
            //list集合不为空即找到对应的用户数据了
            if (userList != null && userList.size() > 0) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean findPhoneByName(String username) {
        if (username != null && username.length() > 0) {
            //使用用户名查询数据库有没有对应数据
            //如果返回的List<Emp>时候查不到数据不为Null,只是size大小为0
            List<User> userList = userMapper.getPhoneByName(username);
            //list集合不为空即找到对应的用户数据了
            if (userList != null && userList.size() > 0) {
                return true;
            }
        }
        return false;
    }

    //添加完用户之后查一下，有就返回true
    @Override
    public boolean addUser(User user) {
        userMapper.addUser(user);
        if (userMapper.getUserByName(user.getUsername() )!= null) {
            return true;
        }
        return false;
    }

    //登录
    @Override
    public User selectUserByNameAndPassword(User user) {
        return userMapper.selectUserByNameAndPassword(user);
    }

    //注册
    @Override
    public int insertUser(User user) {
        return userMapper.insertUser(user);
    }

    //通过id查找用户
    @Override
    public User selectUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    //查找所有用户
    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

}

